//
//  UILoginCodeTextField.m
//  SMealUserSide
//
//  Created by apple on 2018/2/25.
//  Copyright © 2018年 yaozhengzheng. All rights reserved.
//

#import "UILoginCodeTextField.h"


#define UILoginCodeTextField_LeftButtonWidth 180*get6sConstantWidthScale()

#define UILoginCodeTextField_RightButtonWidth 100*get6sConstantWidthScale()

#define UILoginCodeTextField_DefaultMargin  10*get6sConstantWidthScale()

@implementation UILoginCodeTextField

+ (UILoginCodeTextField *)loginCodeTextField
{
    UILoginCodeTextField *codeTextField = [[UILoginCodeTextField alloc]init];
    return codeTextField;
}
- (instancetype)initWithFrame:(CGRect)frame
{
    if(self = [super initWithFrame:frame])
    {
        [self addSubview:self.rightButton];
        [self addSubview:self.leftButton];
        
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    WS(ws)
    [self.leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(ws);
        make.left.equalTo(ws).offset(UILoginCodeTextField_DefaultMargin);
        make.width.mas_equalTo(UILoginCodeTextField_LeftButtonWidth);
    }];
    
    [self.rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(ws);
        make.right.equalTo(ws).offset(-UILoginCodeTextField_DefaultMargin);
        make.width.mas_equalTo(UILoginCodeTextField_RightButtonWidth);
    }];
    
     //内部结构
    CGFloat height = self.bounds.size.height;
    CGFloat width = UILoginCodeTextField_LeftButtonWidth;
    
    CGSize imageSize = self.leftButton.imageView.image.size;
    self.leftButton.imageRect = CGRectMake(width -imageSize.width , (height - imageSize.height)*0.5, imageSize.width, imageSize.height);
    CGRect leftFrame =  self.leftButton.titleLabel.frame;
    self.leftButton.titleRect = CGRectMake(0, leftFrame.origin.y, leftFrame.size.width, leftFrame.size.height);
    
}


#pragma mark - lazy
- (UIButton *)rightButton
{
    if(_rightButton == nil){
        _rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_rightButton setTitle:@"发送验证码" forState:UIControlStateNormal];
        [_rightButton setTitleColor:[UIConstantColor getThemeColor] forState:UIControlStateNormal];
        _rightButton.titleLabel.font = [UIConstantFont getFontW6_H14];
    }
    return _rightButton;
}
- (SMButton *)leftButton
{
    if(_leftButton == nil){
        _leftButton = [SMButton buttonWithType:UIButtonTypeCustom];
        [_leftButton setTitle:@"手机号" forState:UIControlStateNormal];
        [_leftButton setImage:[UIImage imageNamed:@"ico_system_down"] forState:UIControlStateNormal];
        [_leftButton setTitleColor:ZBColorChangeRGB(0xc5c9cc, 1.0) forState:UIControlStateNormal];
        _leftButton.titleLabel.font = [UIConstantFont getFontW6_H14];
        _leftButton.titleLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _leftButton;
}

@end
